package com.longevityassistant.activity.home;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.longevityassistant.activity.BaseActivity;
import com.longevityassistant.activity.R;
import com.longevityassistant.struct.Member;

/**
 * [非登陆区-- 更多]
 * 
 * @author EX-LIBIN005
 * 
 */
public class HomeServerActivity extends BaseActivity {

	protected final String TAG = HomeServerActivity.class.getSimpleName();
	
	public static Member mMember;
	
	/**
	 * 更多 选 项集合
	 */
	private List<GridViewItem> gridViewItemList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_server_activity);
		
		getImageButton1().setVisibility(View.INVISIBLE);
		getImageButton2().setVisibility(View.INVISIBLE);
		
//		setTopImgTitle(R.drawable.logo);
		setTitle(mMember.name+" 长寿助手");
		gridViewItemList = getGridViewItem();

		GridView gvMore = (GridView) findViewById(R.id.gv_server);
		MoreAdapter adapter = new MoreAdapter(this);

		gvMore.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {

				startActivity(gridViewItemList.get(position).intent);
			}
		});

		gvMore.setAdapter(adapter);
		
		cancelMenu();
	}
	
	

	/**
	 * 获取 GridView 数据
	 * 
	 * @return List<GridViewItem>
	 */
	private List<GridViewItem> getGridViewItem() {
		List<GridViewItem> itemList = new ArrayList<GridViewItem>();

		//饮食
		GridViewItem feedBack = new GridViewItem();
		feedBack.icon = R.drawable.selector_home_food_and_drink;
		feedBack.intent = new Intent(this, HomeFoodAndDrinkActivity.class);
		itemList.add(feedBack);
		
		// 睡眠
		GridViewItem helper = new GridViewItem();
		helper.icon = R.drawable.selector_home_sleep;
		helper.intent = new Intent(this, HomeSleepActivity.class);
		itemList.add(helper);
		
		//运动
		GridViewItem creditCard = new GridViewItem();
		creditCard.icon = R.drawable.selector_home_sports;
		creditCard.intent = new Intent(this, HomeSportsActivity.class);
		itemList.add(creditCard);
		
		//健康报告
		GridViewItem faq = new GridViewItem();
		faq.icon = R.drawable.selector_home_health_report;
		faq.intent = new Intent(this, HomeHealthReportActivity.class);
		itemList.add(faq);

		// 健康档案
		GridViewItem exchangeRate = new GridViewItem();
		exchangeRate.icon = R.drawable.selector_home_health_record;
		exchangeRate.intent = new Intent(this,
				HomeHealthRecordActivity.class);
		itemList.add(exchangeRate);

		//药方
		 GridViewItem prescription = new GridViewItem();
		 prescription.icon = R.drawable.selector_home_priscription;
		 prescription.intent = new Intent(this, HomePrescriptionActivity.class);
		 itemList.add(prescription);
		 
		//药箱
		 GridViewItem webStation = new GridViewItem();
		 webStation.icon = R.drawable.selector_home_medical_kit;
		 webStation.intent = new Intent(this, HomeMedicalKitActivity.class);
		 itemList.add(webStation);
		 
		return itemList;

	}

	class GridViewItem {
		int icon;
		Intent intent;
	}

	/**
	 * 更多 GridView 适配器
	 */
	class MoreAdapter extends BaseAdapter {

		private Context context;

		public MoreAdapter(Context context) {
			this.context = context;
		}

		@Override
		public int getCount() {
			if (gridViewItemList != null)
				return gridViewItemList.size();
			return 0;
		}

		@Override
		public Object getItem(int position) {
			return gridViewItemList.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View view, ViewGroup parent) {
			ImageView imageView;
			if (view == null) {

				imageView = new ImageView(context);

				imageView.setLayoutParams(new GridView.LayoutParams(
						GridView.LayoutParams.WRAP_CONTENT,
						GridView.LayoutParams.WRAP_CONTENT));
				imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
				imageView.setPadding(8, 8, 8, 8);
			} else {
				imageView = (ImageView) view;
			}

			imageView.setImageResource(gridViewItemList.get(position).icon);
			return imageView;
		}
	}
	
}
